﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Maticsoft.DBUtility;
namespace Maticsoft.DAL
{
    //QFQCson
    public partial class QFQCson
    {

        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from QFQCson");
            strSql.Append(" where ");
            strSql.Append(" ID = @ID  ");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.QFQCson model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into QFQCson(");
            strSql.Append("FS03,FS04,FS05,FS06,FS07,FS08,FS09,FS10,FS11,FS12,CRP,FS03sum,FS08sum,FS13,FS15,FS14,FS16,FS17,FS18,FS19,FS20,CRT,FS21,FS22,FS23,MODP,MODT,FLAG,AId,FS01,FS02");
            strSql.Append(") values (");
            strSql.Append("@FS03,@FS04,@FS05,@FS06,@FS07,@FS08,@FS09,@FS10,@FS11,@FS12,@CRP,@FS03sum,@FS08sum,@FS13,@FS15,@FS14,@FS16,@FS17,@FS18,@FS19,@FS20,@CRT,@FS21,@FS22,@FS23,@MODP,@MODT,@FLAG,@AId,@FS01,@FS02");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                        new SqlParameter("@FS03", SqlDbType.Int,4) ,
                        new SqlParameter("@FS04", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS05", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS06", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS07", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS08", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS09", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS10", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS11", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS12", SqlDbType.Int,4) ,
                        new SqlParameter("@CRP", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@FS03sum", SqlDbType.NVarChar,400) ,
                        new SqlParameter("@FS08sum", SqlDbType.NVarChar,400) ,
                        new SqlParameter("@FS13", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS15", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS14", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS16", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS17", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS18", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS19", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS20", SqlDbType.Int,4) ,
                        new SqlParameter("@CRT", SqlDbType.DateTime) ,
                        new SqlParameter("@FS21", SqlDbType.Int,4) ,
                        new SqlParameter("@FS22", SqlDbType.Int,4) ,
                        new SqlParameter("@FS23", SqlDbType.Int,4) ,
                        new SqlParameter("@MODP", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@MODT", SqlDbType.DateTime) ,
                        new SqlParameter("@FLAG", SqlDbType.Int,4) ,
                        new SqlParameter("@AId", SqlDbType.VarChar,50) ,
                        new SqlParameter("@FS01", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@FS02", SqlDbType.NVarChar,500)

            };

            parameters[0].Value = model.FS03;
            parameters[1].Value = model.FS04;
            parameters[2].Value = model.FS05;
            parameters[3].Value = model.FS06;
            parameters[4].Value = model.FS07;
            parameters[5].Value = model.FS08;
            parameters[6].Value = model.FS09;
            parameters[7].Value = model.FS10;
            parameters[8].Value = model.FS11;
            parameters[9].Value = model.FS12;
            parameters[10].Value = model.CRP;
            parameters[11].Value = model.FS03sum;
            parameters[12].Value = model.FS08sum;
            parameters[13].Value = model.FS13;
            parameters[14].Value = model.FS15;
            parameters[15].Value = model.FS14;
            parameters[16].Value = model.FS16;
            parameters[17].Value = model.FS17;
            parameters[18].Value = model.FS18;
            parameters[19].Value = model.FS19;
            parameters[20].Value = model.FS20;
            parameters[21].Value = model.CRT;
            parameters[22].Value = model.FS21;
            parameters[23].Value = model.FS22;
            parameters[24].Value = model.FS23;
            parameters[25].Value = model.MODP;
            parameters[26].Value = model.MODT;
            parameters[27].Value = model.FLAG;
            parameters[28].Value = model.AId;
            parameters[29].Value = model.FS01;
            parameters[30].Value = model.FS02;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {

                return Convert.ToInt32(obj);

            }

        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.QFQCson model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update QFQCson set ");

            strSql.Append(" FS03 = @FS03 , ");
            strSql.Append(" FS04 = @FS04 , ");
            strSql.Append(" FS05 = @FS05 , ");
            strSql.Append(" FS06 = @FS06 , ");
            strSql.Append(" FS07 = @FS07 , ");
            strSql.Append(" FS08 = @FS08 , ");
            strSql.Append(" FS09 = @FS09 , ");
            strSql.Append(" FS10 = @FS10 , ");
            strSql.Append(" FS11 = @FS11 , ");
            strSql.Append(" FS12 = @FS12 , ");
            strSql.Append(" CRP = @CRP , ");
            strSql.Append(" FS03sum = @FS03sum , ");
            strSql.Append(" FS08sum = @FS08sum , ");
            strSql.Append(" FS13 = @FS13 , ");
            strSql.Append(" FS15 = @FS15 , ");
            strSql.Append(" FS14 = @FS14 , ");
            strSql.Append(" FS16 = @FS16 , ");
            strSql.Append(" FS17 = @FS17 , ");
            strSql.Append(" FS18 = @FS18 , ");
            strSql.Append(" FS19 = @FS19 , ");
            strSql.Append(" FS20 = @FS20 , ");
            strSql.Append(" CRT = @CRT , ");
            strSql.Append(" FS21 = @FS21 , ");
            strSql.Append(" FS22 = @FS22 , ");
            strSql.Append(" FS23 = @FS23 , ");
            strSql.Append(" MODP = @MODP , ");
            strSql.Append(" MODT = @MODT , ");
            strSql.Append(" FLAG = @FLAG , ");
            strSql.Append(" AId = @AId , ");
            strSql.Append(" FS01 = @FS01 , ");
            strSql.Append(" FS02 = @FS02  ");
            strSql.Append(" where ID=@ID ");

            SqlParameter[] parameters = {
                        new SqlParameter("@ID", SqlDbType.Int,4) ,
                        new SqlParameter("@FS03", SqlDbType.Int,4) ,
                        new SqlParameter("@FS04", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS05", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS06", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS07", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS08", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS09", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS10", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS11", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS12", SqlDbType.Int,4) ,
                        new SqlParameter("@CRP", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@FS03sum", SqlDbType.NVarChar,400) ,
                        new SqlParameter("@FS08sum", SqlDbType.NVarChar,400) ,
                        new SqlParameter("@FS13", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS15", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS14", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS16", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS17", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS18", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS19", SqlDbType.NVarChar,250) ,
                        new SqlParameter("@FS20", SqlDbType.Int,4) ,
                        new SqlParameter("@CRT", SqlDbType.DateTime) ,
                        new SqlParameter("@FS21", SqlDbType.Int,4) ,
                        new SqlParameter("@FS22", SqlDbType.Int,4) ,
                        new SqlParameter("@FS23", SqlDbType.Int,4) ,
                        new SqlParameter("@MODP", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@MODT", SqlDbType.DateTime) ,
                        new SqlParameter("@FLAG", SqlDbType.Int,4) ,
                        new SqlParameter("@AId", SqlDbType.VarChar,50) ,
                        new SqlParameter("@FS01", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@FS02", SqlDbType.NVarChar,500)

            };

            parameters[0].Value = model.ID;
            parameters[1].Value = model.FS03;
            parameters[2].Value = model.FS04;
            parameters[3].Value = model.FS05;
            parameters[4].Value = model.FS06;
            parameters[5].Value = model.FS07;
            parameters[6].Value = model.FS08;
            parameters[7].Value = model.FS09;
            parameters[8].Value = model.FS10;
            parameters[9].Value = model.FS11;
            parameters[10].Value = model.FS12;
            parameters[11].Value = model.CRP;
            parameters[12].Value = model.FS03sum;
            parameters[13].Value = model.FS08sum;
            parameters[14].Value = model.FS13;
            parameters[15].Value = model.FS15;
            parameters[16].Value = model.FS14;
            parameters[17].Value = model.FS16;
            parameters[18].Value = model.FS17;
            parameters[19].Value = model.FS18;
            parameters[20].Value = model.FS19;
            parameters[21].Value = model.FS20;
            parameters[22].Value = model.CRT;
            parameters[23].Value = model.FS21;
            parameters[24].Value = model.FS22;
            parameters[25].Value = model.FS23;
            parameters[26].Value = model.MODP;
            parameters[27].Value = model.MODT;
            parameters[28].Value = model.FLAG;
            parameters[29].Value = model.AId;
            parameters[30].Value = model.FS01;
            parameters[31].Value = model.FS02;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from QFQCson ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;


            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(string where)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from QFQCson ");
            strSql.Append(" where 1=1 and " + where + " ");


            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            return rows;
        }


        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from QFQCson ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.QFQCson GetModel(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID, FS03, FS04, FS05, FS06, FS07, FS08, FS09, FS10, FS11, FS12, CRP, FS03sum, FS08sum, FS13, FS15, FS14, FS16, FS17, FS18, FS19, FS20, CRT, FS21, FS22, FS23, MODP, MODT, FLAG, AId, FS01, FS02  ");
            strSql.Append("  from QFQCson ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;


            Maticsoft.Model.QFQCson model = new Maticsoft.Model.QFQCson();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FS03"].ToString() != "")
                {
                    model.FS03 = int.Parse(ds.Tables[0].Rows[0]["FS03"].ToString());
                }
                model.FS04 = ds.Tables[0].Rows[0]["FS04"].ToString();
                model.FS05 = ds.Tables[0].Rows[0]["FS05"].ToString();
                model.FS06 = ds.Tables[0].Rows[0]["FS06"].ToString();
                model.FS07 = ds.Tables[0].Rows[0]["FS07"].ToString();
                model.FS08 = ds.Tables[0].Rows[0]["FS08"].ToString();
                model.FS09 = ds.Tables[0].Rows[0]["FS09"].ToString();
                model.FS10 = ds.Tables[0].Rows[0]["FS10"].ToString();
                model.FS11 = ds.Tables[0].Rows[0]["FS11"].ToString();
                if (ds.Tables[0].Rows[0]["FS12"].ToString() != "")
                {
                    model.FS12 = int.Parse(ds.Tables[0].Rows[0]["FS12"].ToString());
                }
                model.CRP = ds.Tables[0].Rows[0]["CRP"].ToString();
                model.FS03sum = ds.Tables[0].Rows[0]["FS03sum"].ToString();
                model.FS08sum = ds.Tables[0].Rows[0]["FS08sum"].ToString();
                model.FS13 = ds.Tables[0].Rows[0]["FS13"].ToString();
                model.FS15 = ds.Tables[0].Rows[0]["FS15"].ToString();
                model.FS14 = ds.Tables[0].Rows[0]["FS14"].ToString();
                model.FS16 = ds.Tables[0].Rows[0]["FS16"].ToString();
                model.FS17 = ds.Tables[0].Rows[0]["FS17"].ToString();
                model.FS18 = ds.Tables[0].Rows[0]["FS18"].ToString();
                model.FS19 = ds.Tables[0].Rows[0]["FS19"].ToString();
                if (ds.Tables[0].Rows[0]["FS20"].ToString() != "")
                {
                    model.FS20 = int.Parse(ds.Tables[0].Rows[0]["FS20"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CRT"].ToString() != "")
                {
                    model.CRT = DateTime.Parse(ds.Tables[0].Rows[0]["CRT"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FS21"].ToString() != "")
                {
                    model.FS21 = int.Parse(ds.Tables[0].Rows[0]["FS21"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FS22"].ToString() != "")
                {
                    model.FS22 = int.Parse(ds.Tables[0].Rows[0]["FS22"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FS23"].ToString() != "")
                {
                    model.FS23 = int.Parse(ds.Tables[0].Rows[0]["FS23"].ToString());
                }
                model.MODP = ds.Tables[0].Rows[0]["MODP"].ToString();
                if (ds.Tables[0].Rows[0]["MODT"].ToString() != "")
                {
                    model.MODT = DateTime.Parse(ds.Tables[0].Rows[0]["MODT"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FLAG"].ToString() != "")
                {
                    model.FLAG = int.Parse(ds.Tables[0].Rows[0]["FLAG"].ToString());
                }
                model.AId = ds.Tables[0].Rows[0]["AId"].ToString();
                model.FS01 = ds.Tables[0].Rows[0]["FS01"].ToString();
                model.FS02 = ds.Tables[0].Rows[0]["FS02"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM QFQCson ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * ");
            strSql.Append(" FROM QFQCson ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }


    }
}

